class Project < ActiveRecord::Base

  acts_as_tree :order => "name"
  belongs_to :tracker
  has_many :project_members
  has_many :users, :through => :project_members
  has_many :iterations, :order => "start_date desc"
  has_many :stories, :through => :iterations
  has_many :project_tasks
  
  validates_presence_of :name
  
  def current_iteration 
    today = 0.days.ago.to_s :db #Time.now.strftime('%Y-%m-%d')
    self.iterations.find(:first, 
      :conditions=>"start_date <= '#{today}' and end_date >= '#{today}' ",
      :order=>"start_date desc")  
  end
  
  def current_iteration_resource
    current_iteration.id rescue nil
  end
  
  def work_units_real
    wu=0
    iterations.each do |iteration|
      wu += iteration.work_units_real
    end
    wu
  end  
  
end
